home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / program / tcqbsnip.zip / PERCENT.BAS < prev    next >
BASIC Source File  |  1997-06-20  |  4KB  |  123 lines

  1. '---------------------------------------------------------------------------
  2. 'Percent.bas
  3. 'Original code by Charles Godard 06/22/96
  4. 'Revised by Tika Carr 11/16/96
  5. '  Revisions: o Fixed bugs so that bar can be positioned anywhere, correctly
  6. '               display a centered title, and update properly, no matter what
  7. '               the width or height of box is.
  8. '             o Error checking on Height of box to allow room for text & bar
  9. '             o Fixed colors so they are always definable
  10. '             o Allows you to chose a separate color for the percent bar
  11. '             o Made global variables to position percent box, and define
  12. '               colors & text
  13. '
  14. 'Instructions by Charles Goddard:
  15. '
  16. 'Opens, maintains, then closes a popup box to be used when
  17. 'copying a file or performing other task, to pacify the user
  18. 'while he waits.
  19. '
  20. 'Switch% = 0 turns it on
  21. 'Switch% = 1 maintains it
  22. 'Switch% = 2 closes it
  23. '
  24. 'Pass to it, a number between 1 and 100 and the proper switch
  25. 'PercentBox 0, 0                      'You must 1st open the box
  26. 'PercentBox 1, (Percent%)             'Maintain it with this
  27. 'Percent% MUST be in parenthesis or else MUST be a numeric value.
  28. 'PercentBox 2, 0                      'Close it with this
  29. '
  30. 'Give it a number between 0 and 100, and increment it as needed
  31. 'the delay's, STEP, and for/next are for demo only
  32. '
  33. 'Inspired by reading in the conference.. Alex Wellerstein to James Goldbloom
  34. '---------------------------------------------------------------------------
  35. DEFINT A-Z
  36. DECLARE SUB PercentBox (Switch%, Percent%)
  37.  
  38. TYPE Sdata
  39.    Char  AS STRING * 1
  40.    Attr AS STRING * 1
  41. END TYPE
  42. REDIM SHARED x(25, 80) AS Sdata
  43.  
  44. DIM SHARED by, bx, W, H, bg, fg, bar, Text$
  45.  
  46. '----------------------------- DEMO ----------------------------------------
  47. COLOR , 3: CLS
  48.  
  49. 'Set up box
  50. 'bx and by are the upper left location of the box
  51. 'W and H are the width and height. Anything less than 3 defaults to
  52. '3 so that you have room for the bar and for text above the bar.
  53. 'fg and bg are foreground and background colors, bar is the bar color
  54.  
  55. bx = 20: by = 11: W = 20: H = 1: fg = 15: bg = 1: bar = 14
  56. Text$ = " Progress "
  57. PercentBox 0, 0
  58.  
  59. Dly = 1: GOSUB delay
  60.    FOR Percent% = 1 TO 100 STEP 9
  61.       PercentBox 1, (Percent%)  'you can change the name of
  62.       GOSUB delay               'Percent% and remove the ()
  63.    NEXT Percent%
  64. GOSUB delay
  65.  
  66. PercentBox 2, 0
  67.  
  68. COLOR 7, 0: CLS : END
  69.  
  70. delay:
  71. T& = TIMER: DO WHILE (ABS(T& - TIMER) < Dly) AND INKEY$ = "": LOOP
  72. RETURN
  73. '---------------------------------------------------------------------------
  74.  
  75. SUB PercentBox (Switch%, Percent%)
  76. IF H < 3 THEN H = 3       'Error checking for height
  77. STATIC boxOpen
  78. SELECT CASE Switch%
  79.   CASE IS = 0
  80.     FOR cr = by TO by + H: FOR cc = bx TO bx + W
  81.       x(cr, cc).Char = CHR$(SCREEN(cr, cc))
  82.       x(cr, cc).Attr = CHR$(SCREEN(cr, cc, 1))
  83.     NEXT cc, cr
  84.     FOR cr = by TO by + H
  85.       LOCATE cr, bx: COLOR fg, bg: PRINT STRING$(W, " ")
  86.     NEXT
  87.     boxOpen = 1
  88.     BDRtl = 218: BDRby = 191: BDRbx = 192: BDRrc = 217: 'corners
  89.     BDRv = 179: BDRh = 196:          'horizontal, vertical sides
  90.     COLOR fg, bg
  91.     LOCATE by, bx: PRINT CHR$(BDRtl);  'top lt corner BDR
  92.     FOR i = by TO by + W - 2: PRINT CHR$(BDRh); : NEXT
  93.     LOCATE by, bx + W: PRINT ; CHR$(BDRby);
  94.     FOR i = by + 1 TO by + H - 1:
  95.       LOCATE i, bx: PRINT CHR$(BDRv); : LOCATE i, bx + W: PRINT CHR$(BDRv);
  96.     NEXT
  97.     LOCATE by + H, bx + W: PRINT CHR$(BDRrc);
  98.     LOCATE by + H, bx: PRINT CHR$(BDRbx): LOCATE by + H, bx + 1
  99.     FOR i = bx TO bx + W - 2: PRINT CHR$(BDRh); : NEXT
  100.     LOCATE by, bx + ((W \ 2) - (LEN(Text$) \ 2)): PRINT Text$
  101.   CASE IS = 1 'maintain box
  102.     IF boxOpen = 1 THEN
  103.       'Center percent status according to bx location and W(idth)
  104.       LOCATE by + 1, bx + (W \ 2) - 2: PRINT STR$(Percent%); "%"
  105.       COLOR bar, bg
  106.       Percent% = (Percent% / 100) * (W - 3)     'Bug Fix to allow any size
  107.       LOCATE by + 2, bx + 2: PRINT STRING$(Percent%, 219)
  108.       COLOR fg
  109.     END IF
  110.   CASE IS = 2
  111.     IF boxOpen = 1 THEN
  112.       boxOpen = 0: COLOR fg, bg
  113.       FOR cr = by TO by + H: FOR cc = bx TO bx + W
  114.         LOCATE cr, cc: Attr = ASC(x(cr, cc).Attr)
  115.         fg = Attr AND &HF: bg = Attr \ &H10: COLOR fg, bg
  116.         PRINT x(cr, cc).Char;
  117.       NEXT cc, cr
  118.     END IF
  119.   CASE ELSE
  120. END SELECT
  121. END SUB
  122.  
  123.